package james.gan.remoting.netty.pool;

import java.net.SocketAddress;

import org.apache.commons.pool2.BasePooledObjectFactory;
import org.apache.commons.pool2.PooledObject;
import org.apache.commons.pool2.impl.DefaultPooledObject;
import james.gan.serialization.api.Serialization;

public class NettyClientFactory extends BasePooledObjectFactory<NettyClientProxy> {

	private final SocketAddress socketAddress;
	
	private final Serialization serialization;

	
	public NettyClientFactory(SocketAddress socketAddress, Serialization serialization) {
		super();
		this.socketAddress = socketAddress;
		this.serialization = serialization;
	}

	@Override
	public PooledObject<NettyClientProxy> wrap(NettyClientProxy obj) {
		return new DefaultPooledObject<NettyClientProxy>(obj);
	}

	@Override
	public NettyClientProxy create() throws Exception {
		return new NettyClientProxy(socketAddress, serialization);
	}

}
